/**
 * 
 */
package com.someok.tools.autoproxy;

import java.io.FileWriter;
import java.io.IOException;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.util.Base64Converter;

/**
 * @author wangjxe
 * 
 */
public class Base64Convert extends Task {

	String content;

	String output;

	@Override
	public void execute() throws BuildException {
		if (this.content == null || this.content.trim().length() == 0) {
			return;
		}

		Base64Converter converter = new Base64Converter();
		String outContent = converter.encode(content);
		FileWriter writer = null;
		try {
			writer = new FileWriter(this.output);
			writer.write(outContent);
			
		} catch (IOException e) {
			e.printStackTrace();
			throw new BuildException(e);
		} finally {
			try {
				writer.close();
			} catch (IOException e) {
				e.printStackTrace();
				throw new BuildException(e);
			}
		}
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getOutput() {
		return output;
	}

	public void setOutput(String output) {
		this.output = output;
	}

}
